{include file="common/head"/}
<style>
    .layui-table-cell{height: auto;}
    .layui-table-cell ul li a{color: #1C8FEF;display: block;border: 1px solid #ececec;padding: 3px 8px;}
    .layui-table-cell ul li a:hover{color: #f2f2f2
    }
</style>
<div class="admin-main layui-anim layui-anim-upbit">
    <div style="width: 200px;margin-top: 20px;float:left;height: 665px;background-color: #393D49">
        <ul class="layui-nav layui-nav-tree layui-inline"  lay-filter="demo" style="margin-right: 10px;">
            {volist name="section" id="vo"}

            <li class="layui-nav-item layui-nav-itemed nav-meeting" data-id="{$vo.section_id}">
                <a href="javascript:;">{$vo.title}</a>
            </li>

            {/volist}

        </ul>
    </div>
    <div style="margin-left: 20px;float:left;">
        <table class="layui-table" id="list" lay-filter="list"></table>
    </div>
    <div style="clear: both"></div>
    <div class="layui-btn-group demoTable" style="    position: absolute;right: 67px;">
        <button class="layui-btn" data-type="getCheckData" style="margin-right: 20px">{:lang('submit')}</button>
    </div>


</div>

<script type="text/html" id="sex">
    {{# if(d.sex=='1'){ }}
    男
    {{# }else if(d.sex=='2'){ }}
    女
    {{# }else{ }}
    保密
    {{# } }}
</script>
<script type="text/html" id="status">
    <input type="checkbox" name="is_open" value="{{d.id}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="status" {{ d.status == 1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="barDemo">
    <a href="{:url('teacherEdit')}?id={{d.id}}" class="layui-btn layui-btn-xs">{:lang('edit')}</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">{:lang('del')}</a>
</script>

{include file="common/foot"/}
<script>
    layui.use('table', function() {
        var table = layui.table, $ = layui.jquery;var form = layui.form;
        var all_data = new Array();
        var temp     = new Array();
        var tableIn = table.render({
            id: 'user',
            elem: '#list',
            url: "{:url('teacher')}",
            method: 'post',
            even:true,
            cols: [[
                {type:'checkbox'},
                {field: 'teacher_no',title: '教师编号', width: 130,style:'height: auto;'},
                {field: 'true_name', title: '教师姓名', width: 100,templet:'#name'},
                {field: 'sex', title: '教师性别', width: 100,templet:'#sex'},
                {field: 'title', title: '部门', width: 100},
            ]],
        });
        //监听表格复选框选择
        table.on('checkbox(list)', function(obj){
            console.log(obj.checked);
        });

        $(document).on('click','.nav-meeting',function () {
            var checkStatus = table.checkStatus('user')
                ,data = checkStatus.data;

            for (var i = 0;i<data.length;i++){

                if($.inArray(data[i]['id'], temp)==-1){
                    all_data.push(data[i]);
                    temp.push(data[i]['id']+'');
                }

            }

            var id=$(this).attr('data-id');

            tableIn.reload({
                where: {id:id}
            });

        });

        var active = {
            getCheckData: function(){ //获取选中数据
                var checkStatus = table.checkStatus('user')
                    ,data = checkStatus.data;
                for (var i = 0;i<data.length;i++){
                    if($.inArray(data[i]['id'], temp)==-1){
                        all_data.push(data[i]);
                        temp.push(data[i]['id']+'');
                    }
                }

                $.post('{:url("checkTeacher")}',{all_data:all_data},function (res) {

                    for ( var j = 0 ; j < res.data.length ; j++ ){

                        if($.inArray(res.data[j], temp)!=-1){
                            all_data.splice($.inArray(res.data[j], temp),1);
                            temp.splice($.inArray(res.data[j], temp),1);
                        }

                    }

                    if(res.msg!=''){
                        layer.msg(res.msg);
                    }else {
                        layer.msg('成功');
                    }

                    setTimeout(function () {
                        // 向父页面传值
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.setRel(JSON.stringify(all_data));
                        parent.layer.close(index);
                    },3000);

                });


            }
            ,getCheckLength: function(){ //获取选中数目
                var checkStatus = table.checkStatus('user')
                    ,data = checkStatus.data;
                layer.msg('选中了：'+ data.length + ' 个');
            }
            ,isAll: function(){ //验证是否全选
                var checkStatus = table.checkStatus('user');
                layer.msg(checkStatus.isAll ? '全选': '未全选')
            }
        };
        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            console.log(type);
            active[type] ? active[type].call(this) : '';
        });


    });

</script>
</body>
</html>